package com.usian.article.controller;

import com.usian.apis.article.ApArticleControllerApi;
import com.usian.article.service.ApArticleService;
import com.usian.model.article.pojos.ApArticle;
import com.usian.model.article.pojos.dto.ArticleHomeDto;
import com.usian.model.article.pojos.dto.ArticleInfoDto;
import com.usian.model.common.dtos.ResponseResult;
import org.apache.commons.net.nntp.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController implements ApArticleControllerApi {

    @Autowired
    private ApArticleService articleService;

    @RequestMapping("/selectAllArticle")
    public List<ApArticle> selectAllArticle(){
        return articleService.selectAllArticle();
    }

    @PostMapping("save")
    @Override
    public ApArticle saveArticle(@RequestBody ApArticle apArticle) {
        articleService.save(apArticle);
        return apArticle;
    }

    /**
     * 默认查询
     * @param dto
     * @return
     */
    @PostMapping("/load")
    @Override
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {

        return articleService.load((short)1,dto);
    }

    @PostMapping("/loadmore")
    @Override
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        return articleService.load((short)1,dto);
    }

    @PostMapping("/loadnew")
    @Override
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto) {
        return articleService.load((short)2,dto);
    }


    @PostMapping("/load_article_info")
    @Override
    public ResponseResult loadArticleInfo(@RequestBody  ArticleInfoDto dto) {
        return articleService.loadArticleInfo(dto);
    }
}
